import { Component, Vue, Prop } from 'vue-property-decorator'
@Component({
  name: 'widgetCommon'
})
export default class extends Vue {
  @Prop({ default: undefined }) public value!: any
  @Prop({ default: () => ({}) }) public item!: any
  @Prop({ default: false }) public autoFocus!: boolean
  @Prop({ default: false }) public isConfig!: boolean
  @Prop({ default: false }) public disabled!: boolean
  public blur () {
    this.$emit('fieldBlur', this.value)
  }

  public foucs () {
    this.$nextTick(() => {
      const field = this.$refs.field as any || {}
      if (field.focus) {
        field.focus()
      } else if (field.handleInput) {
        field.handleInput()
      }
    })
  }

  public mounted () {
    if (this.autoFocus) {
      this.foucs()
    }
  }

  // 将最后的值推给父组件，检测变动
  public tableChangeValue () {
    this.changeValue(this.value)
  }

  public onlyChangeValue (v) {
    this.$emit('onlyInput', v)
  }

  public changeValue (v) {
    this.$emit('input', v)
  }
}
